<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" isELIgnored="false"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<base href="<%=basePath%>">
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8" />
	<title>常德快贷平台</title>
	<link rel="stylesheet" href="css/bootstrap.min.css" />
	<link rel="stylesheet" href="css/style1.css" />
	<link rel="stylesheet" href="css/kkpager_blue1.css" />
	<link rel="stylesheet" href="css/jjalert.css" />
	<script src="js/jquery.min.js"></script>
	<script src="js/schedule.js" ></script>
	<script src="js/main1.js" ></script>
	<script src="js/jjalert.js" ></script>
	<style>
	.public_container .leftbar_container a.active:nth-child(3) {
	  background: url(images/my_left_bar_icon_3_new_blue.png) no-repeat 10px center;
	}
	.public_container .leftbar_container a:nth-child(3) {
	  background: url(images/my_left_bar_icon_3_new.png) no-repeat 10px center;
	}
	.public_container .leftbar_container a:nth-child(3):hover {
	  color: #0048b3;
	  font-size: 14px;
	  background: url(images/my_left_bar_icon_3_new_blue.png) no-repeat 10px center;
	  border-left: 4px solid #0048b3;
	}
</style>
<script type="text/javascript">	
window.onload=function(){
	$.ajax({
		url : "<%=request.getContextPath()%>"
		+ '/role/getRoles',
		type : "get",
		contentType : "application/json",
		dataType : "json",
		async : false,
		success : function(data) {
			data.forEach(function (i,index){
				$("#role").append("<option value="+i.role_ID+">"+i.role_NAME+"</option>")
			})
		},
		error : function(data){
			
		}});
}
	function submit(){
		if($("#name").val()==null ||$("#name").val()==''){
			$(".wrong_alert").eq(0).text("请按照格式输入姓名")
			return false;
		}
		if($("#role").val()==null ||$("#role").val()==''){
			$(".wrong_alert").eq(1).text("请选择角色")
			return false;
		}
		if($("#account").val()==null ||$("#account").val()==''){
			$(".wrong_alert").eq(2).text("请输入账号/手机号")
			return false;
		}
		if($("#password").val()==null ||$("#password").val()==''){
			$(".wrong_alert").eq(3).text("请输入密码")
			return false;
		}
		if($("#password2").val()==null ||$("#password2").val()==''){
			$(".wrong_alert").eq(4).text("请再次输入密码")
			return false;
		}
		var role_name=$("#role").find("option:selected").text(); //获取Select选择的text
		var role_id=$("#role").val(); //获取Select选择的Value
		var data = {
				'name': $("#name").val(),
				'role_id':role_id,
				'role_name':role_name,
				'account':$("#account").val(),
				'password':$("#password").val(),
				'fresh':Math.random()
		};
		var path="<%=request.getContextPath()%>";
		 $.ajax({
				url : "<%=request.getContextPath()%>"
				+ '/role/addUser?fresh='+Math.random(),
				data : data,
				type : "get",
				contentType : "application/x-www-form-urlencoded;charset=UTF-8",
				dataType : "json",
				async : false,
				success : function(data) {
					if(data== 'success'){
						jjalert("添加成功");
						window.location.href=path+"/role/account_manage";
					}
					if(data== 'error'){
						jjalert("添加失败");
					}
					if(data =='repeact'){
						jjalert("账号已经存在");
					}
				},
				error : function(data){
					if(data.responseText == 'success'){
						jjalert("添加成功");
						window.location.href=path+"/role/account_manage";
					}
					if(data.responseText == 'error'){
						jjalert("添加失败");
					}
					if(data.responseText =='repeact'){
						jjalert("账号已经存在");
					}
					}
			});
		};
</script>
</head>
<body>
	<div class="public_container">
		
		<div class="nav_container">
			<a href="javascript:void(0)" id="xitongguanli">
				<div class="circle"></div>
				<span>系统管理</span>				
			</a> 
		<%-- <%@ include file="pageHeader2.jsp" %> --%>
		</div>
		<div class="main_container">
			<div class="leftbar_container">
				<a href="role/account_manage">账号管理</a>
				<a class="active" href="role/account_add">添加账号</a>
				<a href="role/account_rolemanage">角色管理</a>
				<a href="role/my_account" class="my_account">我的账户</a>
				<a href="role/account_userAction" class="userAction">用户行为</a>
			</div>
			<div class="right_main_container">
				<div class="customer_add_container">
					<h4>添加账号</h4>
					<div class="customer_add_content">
						<form role="form">
							<div class="input_row form-group">
								<label>姓名</label>
								<input type="text" id="name" class="form-control" />
								<label class="wrong_alert"></label>
							</div>
							<div class="input_row form-group">
								<label>角色</label>
								<select class="form-control" id="role">
								<option value="">请选择</option>
								</select>
								<label class="wrong_alert"></label>
							</div>
							<div class="input_row form-group">
								<label>手机号/账号</label>
								<input  id="account" class="form-control" onkeyup="value=value.replace(/[\W]/g,'') " onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
							<!-- 	<input type="text" id="account" class="form-control" /> -->
								<label class="wrong_alert"></label>
							</div>
							<div class="input_row form-group">
								<label>密码</label>
								<input type="password"  id="password" class="form-control" ><!--  onkeyup="value=value.replace(/[\W]/g,'') " onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" -->
								<label class="wrong_alert"></label>
								<!-- <input type="text" id="password" class="form-control" /> -->								
							</div>
							<div class="input_row form-group">
								<label>确认密码</label>
								<input type="password"  id="password2" class="form-control" ><!--  onkeyup="value=value.replace(/[\W]/g,'') " onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" -->
								<label class="wrong_alert"></label>
								<!-- <input type="text" id="password" class="form-control" /> -->								
							</div>
							<div class="input_row form-group">
								<a href="javascript:;"  class="btn btn-default btn_submit" >提交</a>
							</div>
						</form>
					</div>
				</div>				
			</div>
		</div>		
	</div>
<script>
	$(".btn_submit").click(function(){
		var RegExp = /^[a-zA-Z\u4e00-\u9fa5]+$/;
		if($("#password").val()!=$("#password2").val()){
			$(".wrong_alert").eq(4).text("两次密码输入不一致!")
			$("#password").val("");
			$("#password2").val("");
			return;
		}
		if(RegExp.test($("#name").val())){
			submit();
		} else {
			$(".wrong_alert").eq(0).text("请按照格式输入姓名")
		}
		
	});
</script>	
</body>
</html>